﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ResourceBuilder
{
   public class CssResourceBuilder
   {
      #region Fields
      private DirectoryHelper _directoryHelper = new DirectoryHelper();
      #endregion Fields

      #region Properties
      /// <summary>
      /// Gets the directory helper.
      /// </summary>
      /// <value>The directory helper.</value>
      private DirectoryHelper DirectoryHelper { get { return this._directoryHelper; } }

      /// <summary>
      /// Gets the settings object.
      /// </summary>
      /// <value>The settings.</value>
      private Settings1 Settings { get { return Settings1.Default; } }
      #endregion Properties

      #region Methods
      /// <summary>
      /// Builds the design time CSS.
      /// </summary>
      /// <returns></returns>
      public string BuildDesignTimeCss()
      {
         StringBuilder sb = new StringBuilder();

         foreach (string cssFile in this.Settings.DebugStylesheets)
         {
            using (TextReader trs = new StreamReader(Path.Combine(this.DirectoryHelper.CssAssetsDirectoryPath, cssFile)))
            {
               sb.AppendLine(trs.ReadToEnd());
            }
         }
         sb.AppendLine("a.shp-btn span.shp-ico.Application{background-image: url('<%=WebResource(\"Shp.Web.UI.WebControls.Iconized.assets.im.ico.application.png\")%>');}");
         sb.AppendLine("a.shp-btn span.shp-ico.Image{background-image: url('<%=WebResource(\"Shp.Web.UI.WebControls.Iconized.assets.im.ico.image.png\")%>');}");

         return sb.ToString();
      }

      /// <summary>
      /// Builds the release CSS.
      /// </summary>
      /// <returns></returns>
      public string BuildReleaseCss()
      {
         StringBuilder sb = new StringBuilder();

         foreach (string cssFile in this.Settings.DebugStylesheets)
         {
            using (TextReader trs = new StreamReader(Path.Combine(this.DirectoryHelper.CssAssetsDirectoryPath, cssFile)))
            {
               sb.AppendLine(trs.ReadToEnd());
            }
         }

         return sb.ToString();
      }
      #endregion Methods

      #region Ctors
      public CssResourceBuilder() { }
      #endregion Ctors
   }
}
